import { ElMessageBox, ElMessage } from "element-plus"
import { confirmConfig, TypeType } from "./types"
import { VNode } from "vue"
import useI18n from "@/hooks/useI18n";

const t = useI18n()

/**
 * @description ElMessageBox, ElMessage 消息
 */
export default class MessageUti {
    /**
     * @description 成功消息
     * @param message 消息文字
     */
    public static showSuccess = (message: string) => {
        ElMessage({
            type: 'success',
            message
        })
    }

    /**
     * @description 默认消息
     * @param message 消息文字
     */
    public static showInfo = (message: string) => {
        ElMessage({
            type: 'info',
            message
        })
    }

    /**
     * @description 警告消息
     * @param message 消息文字
     */
    public static showWarning = (message: string) => {
        ElMessage({
            type: 'warning',
            message
        })
    }

    /**
     * @description 失败消息
     * @param message 消息文字
     */
    public static showError = (message: string) => {
        ElMessage({
            type: 'error',
            message
        })
    }

    /**
     * @description MessageBox.confirm 消息弹框
     * @param title 标题
     * @param content 内容
     * @param type 消息类型
     * @returns boolean 
     */
    public static confirm = (title: string, content: string | VNode, type: TypeType = 'warning', config?: confirmConfig): Promise<boolean> => {
        return new Promise((resolve) => {
            ElMessageBox.confirm(content, title, {
                confirmButtonText: t("button.confirm"),
                cancelButtonText: t("button.cancel"),
                type,
                ...config
            })
                .then(() => {
                    resolve(true)
                })
                .catch(() => {
                    resolve(false)
                })
        })
    }
}